package com.qiange.studentmanage.pojo;

import com.qiange.studentmanage.Exception.AgeOutOfBoundsException;
import com.qiange.studentmanage.Exception.WrongFormatException;

import java.text.DateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Student {
    private String sid;
    private String name;
    private int age;
    private String birthday;

    public Student() {
    }

    public Student(String sid, String name, int age, String birthday) {
        this.sid = sid;
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }

    public String getSid() {
        return sid;
    }

    public void setSid(String sid) {
        if (sid.length() != 3) {
            throw new WrongFormatException("学号长度不符合规定");
        }

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() != 4) {
            throw new WrongFormatException("姓名长度不符合规定");
        }

    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 18 || age > 40) {
            throw new AgeOutOfBoundsException("年龄长度不符合规定");
        }

    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {

        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日");

        LocalDate.parse(birthday, dtf);


    }

    @Override
    public String toString() {
        return "Student{" +
                "sid='" + sid + '\'' +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", birthday='" + birthday + '\'' +
                '}';
    }
}
